<template>
  <div class="base-container">
    <t-form ref="form"  :data="queryParams" :label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin: 10px 0px">
        <t-col :span="11" class="query-form-inline" >
          <t-form-item label="体系名称" name="name">
            <t-input
              v-model="queryParams.name"
              clearable
              placeholder="体系名称"
            />
<!--            <t-select>-->

<!--            </t-select>-->
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <div class="btn-group-inline">
      <t-button @click="dialog.header='新增指标体系';dialog.editOpen=true;dialog.objId=0;dialog.open=true" variant="outline" theme="primary">
        <t-icon name="add" slot="icon"/>
        新增指标体系
      </t-button>
    </div>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :loading="dataLoading"
      :pagination="pagination"
    >
      <template #op="{ row }">
        <t-button @click="dialog.header='修改指标体系';dialog.editOpen=true;dialog.objId=row.id;dialog.open = true;" size="small" variant="text"
                  class="t-button-link">
          <t-icon name="edit-1" slot="icon"/>
          修改
        </t-button>
        <t-button theme="danger" @click="handleDel(row)" size="small" variant="text" class="t-button-link">
          <t-icon name="delete" slot="icon"/>
          删除
        </t-button>
      </template>
      <template #reviewCount="{ row }">
        <t-link @click="dialog.objId=row.id;dialog.header=row.name;dialog.open_list=true" hover="color" theme="primary">{{row.reviewCount}}</t-link>
      </template>
    </t-table>
    <add-edit-review-standard  @reload="getList()" :header="dialog.header" :editOpen="dialog.editOpen" :objId="dialog.objId" :visible.sync="dialog.open"
                               v-if="dialog.open"></add-edit-review-standard>
    <review-standard-list   :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_list"
                            v-if="dialog.open_list"></review-standard-list>
  </div>
</template>

<script >
import AddEditReviewStandard from './components/add-edit-review-standard.vue'
import ReviewStandardList from './components/review-standard-list.vue'

export default {
  name: "review-standard-index",
  components:{
    AddEditReviewStandard,
    ReviewStandardList
  },
  data(){
    return {
      dialog:{
        header:'',
        objId:0,
        open: false,
        editOpen:false,
        open_list: false
      },
      total:0,
      totalQuota:0,
      data:[],
      columns:[
        {
          colKey: "name",
          title: "配置名称",
          align: "center",
          ellipsis: true
        },
        {
          colKey: "reviewCount",
          title: "指标个数",
          align: "center",
          width: 120
        },
        {
          colKey: "score",
          title: "总分值",
          align: "center",
          width: 120
        },
        {
          colKey: "createTime",
          title: "创建时间",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width:250
        },
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        departmentName:"",
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created() {
    this.getList();
  },
  methods:{
    getList(){
      this.dataLoading = true;
      this.$api.kjpt.examine.indexList(this.queryParams).then(
        (res) => {
          this.data = res.rows;
          this.pagination.total = res.total;
          this.dataLoading = false;
        }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    handleDel(row) {
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除体系名称为"${row.name}"的数据项？`,
        theme: "warning",
        onConfirm: ({e}) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.$api.kjpt.examine.indexDel(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        },
      })
    },
  }
}
</script>

<style scoped>

</style>
